﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using HardMobInfra.Services;
using System.Net;

namespace TopicInfoWeb
{
	public class CacheGerente
	{
		private const string CacheItemTemp = "CacheItemSimuladorServico";
		public const string DummyPageUrl = "http://localhost:54008/Home/ActionForCacheCreation";

		public void RegistrarEntradaCache()
		{
			if (null != HttpContext.Current.Cache[CacheItemTemp])
				return;

			HttpContext.Current.Cache.Add(CacheItemTemp, "CacheItemSimuladorServico", null,
				DateTime.MaxValue, TimeSpan.FromMinutes(2),
				CacheItemPriority.Normal,
				new CacheItemRemovedCallback(CacheItemRemovedCallback));

		}

		public void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
		{
			//new DebugServerService().RegistrarCacheCriado();
			HitPage();
		}

		public void HitPage()
		{
			WebClient client = new WebClient();
			
			client.DownloadData(DummyPageUrl);
		}
	}
}